package com.xg.aixintanchuangdemo.controller;

import com.xg.aixintanchuangdemo.service.HeartMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 爱心弹窗API控制器
 * 提供文段数据接口
 */
@RestController
@RequestMapping("/api")
public class HeartController {
    
    @Autowired
    private HeartMessageService heartMessageService;
    
    /**
     * 获取所有文段
     * @return 包含所有文段和数量的响应
     */
    @GetMapping("/messages")
    public Map<String, Object> getAllMessages() {
        Map<String, Object> response = new HashMap<>();
        response.put("messages", heartMessageService.getAllMessages());
        response.put("count", heartMessageService.getMessageCount());
        return response;
    }
    
    /**
     * 获取随机文段
     * @return 随机文段
     */
    @GetMapping("/message/random")
    public Map<String, String> getRandomMessage() {
        Map<String, String> response = new HashMap<>();
        response.put("message", heartMessageService.getRandomMessage());
        return response;
    }
}

